package demo03;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/10/31 15:03
 */
public class Ticket implements Runnable{
    private Object lock=new Object();
    private int tickets=100;
    @Override
    public void run() {
        while (true){
            synchronized (lock) {
                if (tickets > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖了一张票,剩余" + --tickets + "张");
                } else {
                    break;
                }
            }
        }
    }
}
